<template>
	<view class="mine-page">
		<view class="top-box"
			:style="{background: `url(${baseImgUrl}images_bg1.png) no-repeat;background-size: cover`}">
			<view class="nav-bar" :style="{ height: navBarHeight }"></view>
			<view class="user-info">
				<view class="user-img">
					<!-- <image class="user-head" :src="avatar" mode="aspectFill" /> -->
					<image class="user-head" src="/static/images/acquiesce.jpg" mode="widthFix"></image>
				</view>
				<view class="info-box">
					<view class="user-name">
						<view class="name">{{ userInfo.name }}</view>
						<view class="member"></view>
					</view>
					<view class="id">ID：{{ userInfo.id }}</view>
				</view>
				<view class="setting-icon" @click="editUser">
					<image class="icon" :src="baseIconUrl + 'icon_setting.png'" mode="aspectFill" />
				</view>
			</view>
			<view class="order-box">
				<view class="title-box">
					<view class="title">我的订单</view>
					<view class="more" @click="clickOrderItem()">
						全部
						<image class="more-icon" :src="baseIconUrl + 'icon_right.png'" mode="aspectFill" />
					</view>
				</view>
				<view class="order-list">
					<view class="order-item" v-for="(item, index) in orderConfig" :key="index">
						<view class="icon-box" @click="clickOrderItem(item)">
							<image class="order-icon" :src="baseIconUrl + item.icon" mode="aspectFill" />
						</view>
						<view class="name">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cell-box">
			<view class="cell-item" v-for="(item, index) in cellConfig" :key="index" @click="clickCellItem(item)">
				<view class="cell-icon">
					<image class="cell-img" :src="baseIconUrl + item.icon" mode="scaleToFill" />
				</view>
				<view class="name">{{ item.name }}</view>
				<view class="right-icon">
					<image class="arrow-img" :src="baseIconUrl + 'icon_right1.png'" mode="scaleToFill" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseIconUrl,
		baseImgUrl
	} from '@/config'
	export default {
		name: 'UserCenter',

		data() {
			return {
				baseIconUrl,
				baseImgUrl,
				navBarHeight: '',
				avatar: 'https://rb.biomedical-wh.com/prod-api/profile/upload/fangxiStatis/icons/icon_head.png',
				userInfo: {
					name: '微信用户',
					member: true,
					id: '无'
				},
				orderConfig: [{
						name: '待发货',
						key: '1',
						icon: 'icon_wait.png'
					},
					{
						name: '待收货',
						key: '3',
						icon: 'icon_take.png'
					},
					{
						name: '已完成',
						key: '4',
						icon: 'icon_complete.png'
					},
					{
						name: '退款',
						key: '5',
						icon: 'icon_refund.png'
					}
				],
				cellConfig: [{
						name: '地址管理',
						key: 1,
						icon: 'icon_address.png',
						pageUrl: '/subPages/store/myAddress'
					},
					{
						name: '成为商户',
						key: 2,
						icon: 'icon_privacy.png',
						pageUrl: '/subPages/otherPages/becomeMerchant'
					},
					{
						name: '成为供应商',
						key: 3,
						icon: 'icon_user.png',
						pageUrl: '/subPages/otherPages/becomeSupplier'
					},
					{
						name: '用户协议',
						key: 4,
						icon: 'icon_user.png',
						pageUrl: '/subPages/otherPages/wxHtml?id=3'
					},
					{
						name: '隐私协议',
						key: 5,
						icon: 'icon_privacy.png',
						pageUrl: '/subPages/otherPages/wxHtml?id=2'
					},
					{
						name: '关于我们',
						key: 6,
						icon: 'icon_about.png',
						pageUrl: '/subPages/otherPages/wxHtml?id=1'
					}
				]
			}
		},

		onLoad() {
			this.navBarHeight = this.$store.getters.heightData.navBarHeight + 'px'
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			async getUserInfo() {
				const res = await this.$GET('/fx/user/getInfo')
				if (res.code == 200) {
					console.log(res)
					this.avatar = res.data.userPhoto.includes('http') ? res.data.userPhoto :
						`${this.baseUrl}${res.data.userPhoto}`
					this.userInfo.name = res.data.userName
					this.userInfo.id = res.data.sysUserid
				}
			},
			clickOrderItem(item) {
				console.log('皮', item)
				uni.reLaunch({
					url: `/pages/order?orderStatus=${item.key}`
				})
			},
			async clickCellItem(item) {
				if (item.key !== 3 && item.key !== 2) {
					uni.navigateTo({
						url: item.pageUrl
					})
				} else if (item.key === 3) {
					let res = await this.$GET(`/fx/join/toApply?type=${3}`)
					if (res.data.status === 0) {
						uni.navigateTo({
							url: `/subPages/otherPages/underReview`
						})
					} else if (res.data.status === 1) {
						uni.navigateTo({
							url: `${item.pageUrl}?status=1`
						})
						// uni.navigateTo({
						// 	url: `/subPages/otherPages/supplierOrder`
						// })
						// uni.setStorageSync('roleId', 3)
					} else if (res.data.status === 2) {
						uni.navigateTo({
							url: `${item.pageUrl}?status=2`
						})
					} else {
						uni.navigateTo({
							url: item.pageUrl
						})
					}
				} else if (item.key === 2) {
					let res = await this.$GET(`/fx/join/toApply?type=${4}`)
					if (res.data.status === 0) {
						uni.navigateTo({
							url: `/subPages/otherPages/underReview`
						})
					} else if (res.data.status === 1) {
						uni.navigateTo({
							url: `${item.pageUrl}?status=1`
						})
						// uni.navigateTo({
						// 	url: `/subPages/otherPages/businessOrder`
						// })
						// uni.setStorageSync('roleId', 4)
					} else if (res.data.status === 2) {
						uni.navigateTo({
							url: `${item.pageUrl}?status=2`
						})
					} else {
						uni.navigateTo({
							url: item.pageUrl
						})
					}
				}

			},
			editUser() {
				uni.navigateTo({
					url: "/subPages/userCenter/editUserInfo"
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.top-box {

		// background: linear-gradient(to bottom, #2da884, #f2f2f2);
		.user-info {
			display: flex;
			padding: 20rpx 28rpx 40rpx;

			.user-img {
				width: 120rpx;
				height: 120rpx;
				border-radius: 60rpx;
				overflow: hidden;

				// background-color: #f4e2cc;
				.user-head {
					width: 100%;
					height: 100%;
				}
			}

			.info-box {
				flex: 1;
				margin: 0 20rpx;

				.user-name {
					display: flex;
					align-items: center;

					.name {
						margin-bottom: 14rpx;
						font-size: 36rpx;
						font-weight: 500;
						color: #FFF;
					}
				}

				.id {
					font-size: 24rpx;
					color: #FFF;
				}
			}

			.setting-icon {
				width: 48rpx;
				height: 48rpx;

				.icon {
					width: 100%;
					height: 100%;
				}
			}
		}

		.order-box {
			padding: 24rpx;
			margin: 0 28rpx;
			border-radius: 12rpx;
			background-color: #FFF;

			.title-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;

				.title {
					font-size: 30rpx;
					font-weight: 500;
				}

				.more {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #999;

					.more-icon {
						width: 34rpx;
						height: 34rpx;
						margin-left: 10rpx;
					}
				}
			}

			.order-list {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.order-item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.icon-box {
						width: 48rpx;
						height: 48rpx;

						.order-icon {
							width: 100%;
							height: 100%;
						}
					}

					.name {
						color: #999;
					}
				}
			}
		}
	}

	.cell-box {
		padding: 0 32rpx;
		margin: 20rpx 28rpx 0;
		border-radius: 12rpx;
		background-color: #FFF;

		.cell-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 122rpx;

			.cell-icon {
				width: 42rpx;
				height: 42rpx;

				.cell-img {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				flex: 1;
				font-size: 30rpx;
				font-weight: 500;
				margin-left: 40rpx;
			}

			.right-icon {
				width: 42rpx;
				height: 42rpx;

				.arrow-img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>